#include<iostream>

using namespace std;
const int N = 1e6 + 10;
int a[N];
using ll = long long;
int main()
{
    int n; cin >> n;

    int v1, v2, v3, v4, v5, v6;
    cin >> v1 >> v2 >> v3 >> v4 >> v5 >> v6;
    int count = 1, ret = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i])
        {
            if (count < 3) ret += v1;
            else if (count >= 3 && count < 7) ret += v2;
            else if (count >= 7 && count < 30) ret += v3;
            else if (count >= 30 && count < 120) ret += v4;
            else if (count >= 120 && count < 365) ret += v5;
            else ret += v6;
            count ++;
        }
        else count = 1;
    }

    cout << ret << endl;
    return 0;
}